<template>
</template>

<script>
	export default {
		data() {
			return {}
		},
		onLoad(info) {
			let code = this.GetQueryString('code')
			if (code !== '' && code != null && code !== undefined && code !== 'undefined') {
				this.initData(code)
			}
		},
		methods: {
			initData(code) {
				this.$request('/auth/loginByMp', {
					code: code,
					projectId:'zjjjhyl',
					scope:1 // 静默登录才传scope，授权不需要scope
				}, 'POST').then(res => {
					console.log(res, '换取token')
					// uni.setStorageSync('token', res.token);
					sessionStorage.setItem('token',res.token)
					uni.setStorageSync('user', res.user);
					uni.setStorageSync('openId', res.openId);
					console.log(uni.getStorageSync('localUrl'))
					location.href = uni.getStorageSync('localUrl')
					// uni.redirectTo({
					// 	url: uni.getStorageSync('localUrl')
					// });
				})
			},
			GetQueryString(name) {
				var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)')
				var r = window.location.search.substr(1).match(reg)
				if (r != null) return unescape(r[2])
				return null
			}
		}
	}
</script>

<style>
</style>
